/**
 * @file prmask.c
 * @author liangwenhao (1943080020@qq.com)
 * @brief 
 * @version 0.1
 * @date 2021-07-29
 * 
 * @copyright Copyright (c) 2021
 * 
 * @authorGitee  https://gitee.com/liangwenhao
 * @authorGithub https://github.com/WHaoL
 * @authorBlogs https://blog.csdn.net/liangwenhao1108
 *  
 * @Code Description: P275-276 打印 调用进程 信号屏蔽字中的信号 
 *  
 */

#include "apue.h"
#include <errno.h>

void pr_mask(const char *str)
{
	sigset_t sigset;
	int errno_save;

	errno_save = errno;							   /* we can be called by signal handlers */
	if (sigprocmask(SIG_BLOCK, NULL, &sigset) < 0) //先获取 当前进程的 信号屏蔽字
	{
		err_ret("sigprocmask error");
	}
	else
	{
		printf("%s", str);
		if (sigismember(&sigset, SIGINT))
			printf(" SIGINT");
		if (sigismember(&sigset, SIGQUIT))
			printf(" SIGQUIT");
		if (sigismember(&sigset, SIGUSR1))
			printf(" SIGUSR1");
		if (sigismember(&sigset, SIGALRM))
			printf(" SIGALRM");

		/* remaining signals can go here  */

		printf("\n");
	}

	errno = errno_save; /* restore errno */ //保护现场
}
